import pymysql

db = pymysql.connect(
    host='localhost',
    port=3306,
    database='jiangsu',
    user='root',
    password='root',
    charset='utf8'
)

cursor = db.cursor()
sql = 'select * from student'

cursor.execute(sql)
# fatchall 获取所有结果
data = cursor.fetchall()
for row in data:
    print(row)
# fatchone  获取一个结果
print('-------------------------\n')
cursor.execute(sql)
data1 = cursor.fetchone()
print(data1)
print('--------------------------\n')

# fatchmany(获取指定数量结果)
# cursor.execute(sql)
data2 = cursor.fetchmany(3)
print(data2)

cursor.close()
db.close()
